﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ProgressBarExtensions.cs" company="Jarno Burger">
//   Jarno Burger
// </copyright>
// <summary>
//   Defines the ProgressBarExtensions type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace MyDomotica
{
    using System;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Media.Animation;

    /// <summary>
    /// This extensions make it possible to set a animated progress to next value on the progress bar.
    /// </summary>
    public static class ProgressBarExtensions
    {
        /// <summary>The Duration of the animation to move towards the new percentage value.</summary>
        private static readonly TimeSpan Duration = TimeSpan.FromSeconds(0.2);

        /// <summary>
        /// Sets the percent to given progress-bar.
        /// </summary>
        /// <param name="progressBar">The progress bar.</param>
        /// <param name="percentage">The percentage.</param>
        public static void SetPercent(this ProgressBar progressBar, double percentage)
        {
            var animation = new DoubleAnimation(percentage, Duration);
            progressBar.BeginAnimation(RangeBase.ValueProperty, animation);
        }
    }
}
